<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  
  <title>mysql8.0安装 liunx 安装 | 阿冰的个人博客</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="官网下载地址:https:&#x2F;&#x2F;downloads.mysql.com&#x2F;archives&#x2F;get&#x2F;p&#x2F;23&#x2F;file&#x2F;mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz清理原有mysql环境123456rpm -qa | grep -i mysql | xargs yum remove -yrpm -qa | grep -i mariadb | xargs yum">
<meta property="og:type" content="article">
<meta property="og:title" content="mysql8.0安装 liunx 安装">
<meta property="og:url" content="https://wbc389561407.github.io/2023/07/12/mysql8.0-liunx%E5%AE%89%E8%A3%85/index.html">
<meta property="og:site_name" content="阿冰的个人博客">
<meta property="og:description" content="官网下载地址:https:&#x2F;&#x2F;downloads.mysql.com&#x2F;archives&#x2F;get&#x2F;p&#x2F;23&#x2F;file&#x2F;mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz清理原有mysql环境123456rpm -qa | grep -i mysql | xargs yum remove -yrpm -qa | grep -i mariadb | xargs yum">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2023-07-12T06:21:45.771Z">
<meta property="article:modified_time" content="2023-07-12T06:56:27.447Z">
<meta property="article:author" content="wangbingchen">
<meta property="article:tag" content="mysql">
<meta property="article:tag" content="liunx">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/atom.xml" title="阿冰的个人博客" type="application/atom+xml">
  
  
    <link rel="shortcut icon" href="/favicon.png">
  
  
    
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/typeface-source-code-pro@0.0.71/index.min.css">

  
  
<link rel="stylesheet" href="/css/style.css">

  
    
<link rel="stylesheet" href="/fancybox/jquery.fancybox.min.css">

  
  
<meta name="generator" content="Hexo 6.3.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">阿冰的个人博客</a>
      </h1>
      
        <h2 id="subtitle-wrap">
          <a href="/" id="subtitle">学习的内容太多,学过忘记的太多,便于记忆,零碎整理的博客</a>
        </h2>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"><span class="fa fa-bars"></span></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
        
          <a class="nav-icon" href="/atom.xml" title="RSS 订阅"><span class="fa fa-rss"></span></a>
        
        <a class="nav-icon nav-search-btn" title="搜索"><span class="fa fa-search"></span></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="搜索"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="https://wbc389561407.github.io"></form>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main"><article id="post-mysql8.0-liunx安装" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/2023/07/12/mysql8.0-liunx%E5%AE%89%E8%A3%85/" class="article-date">
  <time class="dt-published" datetime="2023-07-12T06:21:45.771Z" itemprop="datePublished">2023-07-12</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/liunx/">liunx</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="p-name article-title" itemprop="headline name">
      mysql8.0安装 liunx 安装
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h3 id="官网下载地址-https-downloads-mysql-com-archives-get-p-23-file-mysql-8-0-20-linux-glibc2-12-x86-64-tar-xz"><a href="#官网下载地址-https-downloads-mysql-com-archives-get-p-23-file-mysql-8-0-20-linux-glibc2-12-x86-64-tar-xz" class="headerlink" title="官网下载地址:https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz"></a>官网下载地址:<a target="_blank" rel="noopener" href="https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz">https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz</a></h3><h3 id="清理原有mysql环境"><a href="#清理原有mysql环境" class="headerlink" title="清理原有mysql环境"></a>清理原有mysql环境</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">rpm -qa | grep -i mysql | xargs yum remove -y</span><br><span class="line"></span><br><span class="line">rpm -qa | grep -i mariadb | xargs yum remove -y</span><br><span class="line"></span><br><span class="line">find / -name mysql | xargs rm -rf</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="解压文件比较耗时间"><a href="#解压文件比较耗时间" class="headerlink" title="解压文件比较耗时间"></a>解压文件比较耗时间</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">tar -xvf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz</span><br></pre></td></tr></table></figure>

<h3 id="第一步复制下面所有"><a href="#第一步复制下面所有" class="headerlink" title="第一步复制下面所有"></a>第一步复制下面所有</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">#移动文件重命名</span><br><span class="line">mv mysql-8.0.20-linux-glibc2.12-x86_64 /usr/local/mysql</span><br><span class="line"></span><br><span class="line">#添加用户组</span><br><span class="line">cat /etc/group | grep mysql</span><br><span class="line">cat /etc/passwd |grep mysql</span><br><span class="line">groupadd mysql</span><br><span class="line">useradd -r -g mysql mysql</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"># 创建文件夹</span><br><span class="line">mkdir /usr/local/mysql/data</span><br><span class="line"></span><br><span class="line"># 给文件夹授权</span><br><span class="line">chown -R root:root /usr/local/mysql</span><br><span class="line"># 给文件夹授权</span><br><span class="line">chown -R mysql:mysql /usr/local/mysql/data/</span><br><span class="line"># 初始化数据库，mysql的bin目录下的mysqld命令</span><br><span class="line">/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data</span><br></pre></td></tr></table></figure>

<h3 id="完成之后看到-最后一行"><a href="#完成之后看到-最后一行" class="headerlink" title="完成之后看到 最后一行"></a>完成之后看到 最后一行</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">2021-03-28T05:48:33.232241Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: =vd(4KS6kpic</span><br></pre></td></tr></table></figure>
<h3 id="得到初始化密码-x3D-vd-4KS6kpic"><a href="#得到初始化密码-x3D-vd-4KS6kpic" class="headerlink" title="得到初始化密码 &#x3D;vd(4KS6kpic"></a>得到初始化密码 &#x3D;vd(4KS6kpic</h3><h3 id="检测命令-可忽略"><a href="#检测命令-可忽略" class="headerlink" title="检测命令 可忽略"></a>检测命令 可忽略</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">rpm -qa|grep libaio</span><br><span class="line">#</span><br><span class="line">yum install libaio-devel.x86_64</span><br><span class="line">#</span><br><span class="line">yum -y install numactl</span><br></pre></td></tr></table></figure>


<h3 id="配置mysql启动文件"><a href="#配置mysql启动文件" class="headerlink" title="配置mysql启动文件"></a>配置mysql启动文件</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">touch /usr/local/mysql/support-files/my-default.cnf</span><br><span class="line">chmod 777 /usr/local/mysql/support-files/my-default.cnf</span><br><span class="line">cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf</span><br><span class="line">vi /etc/my.cnf</span><br></pre></td></tr></table></figure>

<h3 id="执行完上面的后-已经进入了my-cnf文件里面-直接复制下面内容"><a href="#执行完上面的后-已经进入了my-cnf文件里面-直接复制下面内容" class="headerlink" title="执行完上面的后 已经进入了my.cnf文件里面 直接复制下面内容"></a>执行完上面的后 已经进入了my.cnf文件里面 直接复制下面内容</h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line">[mysqld]</span><br><span class="line"></span><br><span class="line"># Remove leading # and set to the amount of RAM for the most important data</span><br><span class="line"># cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.</span><br><span class="line"># innodb_buffer_pool_size = 128M</span><br><span class="line"></span><br><span class="line"># Remove leading # to turn on a very important data integrity option: logging</span><br><span class="line"># changes to the binary log between backups.</span><br><span class="line"># log_bin</span><br><span class="line"></span><br><span class="line"># These are commonly set, remove the # and set as required.</span><br><span class="line">basedir = /usr/local/mysql</span><br><span class="line">datadir = /usr/local/mysql/data</span><br><span class="line">socket = /tmp/mysql.sock</span><br><span class="line">log-error = /usr/local/mysql/data/error.log</span><br><span class="line">pid-file = /usr/local/mysql/data/mysql.pid</span><br><span class="line">port = 3306</span><br><span class="line">#lower_case_table_names = 1</span><br><span class="line"># server_id = .....</span><br><span class="line"># socket = .....</span><br><span class="line">#lower_case_table_names = 1</span><br><span class="line">max_allowed_packet=32M</span><br><span class="line">default-authentication-plugin = mysql_native_password</span><br><span class="line">#lower_case_file_system = on</span><br><span class="line">#lower_case_table_names = 1</span><br><span class="line">log_bin_trust_function_creators = ON</span><br><span class="line"># Remove leading # to set options mainly useful for reporting servers.</span><br><span class="line"># The server defaults are faster for transactions and fast SELECTs.</span><br><span class="line"># Adjust sizes as needed, experiment to find the optimal values.</span><br><span class="line"># join_buffer_size = 128M</span><br><span class="line"># sort_buffer_size = 2M</span><br><span class="line"># read_rnd_buffer_size = 2M</span><br><span class="line"></span><br><span class="line">sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES</span><br></pre></td></tr></table></figure>
<h4 id="my-cnf配置完成"><a href="#my-cnf配置完成" class="headerlink" title="my.cnf配置完成"></a>my.cnf配置完成</h4><h3 id="设置开机启动数据库"><a href="#设置开机启动数据库" class="headerlink" title="设置开机启动数据库"></a>设置开机启动数据库</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql</span><br><span class="line"></span><br><span class="line">chmod +x /etc/init.d/mysql</span><br><span class="line"></span><br></pre></td></tr></table></figure>


<h3 id="注册"><a href="#注册" class="headerlink" title="注册"></a>注册</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">chkconfig --add mysql</span><br></pre></td></tr></table></figure>
<h3 id="检测"><a href="#检测" class="headerlink" title="检测"></a>检测</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">chkconfig --list mysql</span><br></pre></td></tr></table></figure>
<h3 id="配置ld-so-conf-添加如下内容-x2F-usr-x2F-local-x2F-mysql-x2F-lib"><a href="#配置ld-so-conf-添加如下内容-x2F-usr-x2F-local-x2F-mysql-x2F-lib" class="headerlink" title="配置ld.so.conf 添加如下内容 &#x2F;usr&#x2F;local&#x2F;mysql&#x2F;lib"></a>配置ld.so.conf 添加如下内容 &#x2F;usr&#x2F;local&#x2F;mysql&#x2F;lib</h3><h4 id="打开文件ld-so-conf命令"><a href="#打开文件ld-so-conf命令" class="headerlink" title="打开文件ld.so.conf命令:"></a>打开文件ld.so.conf命令:</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vi /etc/ld.so.conf</span><br></pre></td></tr></table></figure>
<h3 id="添加如下内容加入配置文件ld-so-conf"><a href="#添加如下内容加入配置文件ld-so-conf" class="headerlink" title="添加如下内容加入配置文件ld.so.conf"></a>添加如下内容加入配置文件ld.so.conf</h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">/usr/local/mysql/lib</span><br></pre></td></tr></table></figure>


<h3 id="配置环境变量-打开profile文件"><a href="#配置环境变量-打开profile文件" class="headerlink" title="配置环境变量 打开profile文件"></a>配置环境变量 打开profile文件</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vi /etc/profile</span><br></pre></td></tr></table></figure>

<h3 id="在-x2F-etc-x2F-profile-添加如下内容"><a href="#在-x2F-etc-x2F-profile-添加如下内容" class="headerlink" title="在 &#x2F;etc&#x2F;profile 添加如下内容"></a>在 &#x2F;etc&#x2F;profile 添加如下内容</h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"># MYSQL ENVIRONMENT</span><br><span class="line">export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib</span><br></pre></td></tr></table></figure>


<h3 id="系统重新加载文件，记得一定要，记得一定要，记得一定要"><a href="#系统重新加载文件，记得一定要，记得一定要，记得一定要" class="headerlink" title="系统重新加载文件，记得一定要，记得一定要，记得一定要"></a>系统重新加载文件，记得一定要，记得一定要，记得一定要</h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">source /etc/profile</span><br></pre></td></tr></table></figure>

<h3 id="启动mysql"><a href="#启动mysql" class="headerlink" title="启动mysql"></a>启动mysql</h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">service mysql start</span><br></pre></td></tr></table></figure>


<h3 id="连接数据库"><a href="#连接数据库" class="headerlink" title="连接数据库"></a>连接数据库</h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mysql -uroot -p</span><br></pre></td></tr></table></figure>

<h3 id="输入密码"><a href="#输入密码" class="headerlink" title="输入密码"></a>输入密码</h3><h3 id="数据库mysql-gt-里面操作"><a href="#数据库mysql-gt-里面操作" class="headerlink" title="数据库mysql&gt;里面操作"></a>数据库mysql&gt;里面操作</h3><h5 id="修改密码"><a href="#修改密码" class="headerlink" title="修改密码"></a>修改密码</h5><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">alter user &#x27;root&#x27;@&#x27;localhost&#x27; identified by &#x27;12345678&#x27;;</span><br></pre></td></tr></table></figure>


<h3 id="开放远程连接"><a href="#开放远程连接" class="headerlink" title="开放远程连接"></a>开放远程连接</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">use mysql;</span><br><span class="line">update user set host = &#x27;%&#x27; where user = &#x27;root&#x27;;</span><br><span class="line">flush privileges;</span><br></pre></td></tr></table></figure>
<h3 id="navicat可以连接了"><a href="#navicat可以连接了" class="headerlink" title="navicat可以连接了"></a>navicat可以连接了</h3>
      
    </div>
    <footer class="article-footer">
      <a data-url="https://wbc389561407.github.io/2023/07/12/mysql8.0-liunx%E5%AE%89%E8%A3%85/" data-id="cljzdc3vf00007cyj5xv799vw" data-title="mysql8.0安装 liunx 安装" class="article-share-link"><span class="fa fa-share">分享</span></a>
      
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/liunx/" rel="tag">liunx</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/mysql/" rel="tag">mysql</a></li></ul>

    </footer>
  </div>
  
    
  
</article>


</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">分类</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/liunx/">liunx</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">标签</h3>
    <div class="widget">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/tags/liunx/" rel="tag">liunx</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mysql/" rel="tag">mysql</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">标签云</h3>
    <div class="widget tagcloud">
      <a href="/tags/liunx/" style="font-size: 10px;">liunx</a> <a href="/tags/mysql/" style="font-size: 10px;">mysql</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">归档</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2023/07/">七月 2023</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2023/07/12/mysql8.0-liunx%E5%AE%89%E8%A3%85/">mysql8.0安装 liunx 安装</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      
      &copy; 2023 wangbingchen<br>
      Powered by <a href="https://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>

    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    


<script src="/js/jquery-3.6.4.min.js"></script>



  
<script src="/fancybox/jquery.fancybox.min.js"></script>




<script src="/js/script.js"></script>





  </div>
</body>
</html>